package cn.yuan.order.controller;

import cn.yuan.basic.Exception.BusinessException;
import cn.yuan.basic.util.LoginContext;
import cn.yuan.order.service.IProductOrderService;
import cn.yuan.user.domain.Logininfo;
import cn.yuan.util.AjaxResult.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {

    @Autowired
    private IProductOrderService productOrderService;
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try {
            Logininfo loginInfo = LoginContext.getLoginInfo(request);
            //为支付准备的回调
            String payData = productOrderService.submit(params,loginInfo);
            return AjaxResult.me().setResultObj(payData);
        }catch(BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("系统错误");
        }

    }
}
